<?php

/**
 * @author TEAM03-HEDSPI
 * @copyright 2012
 * @description ????????????????
 */
include_once('ConnectionDatabase.php');
class Menu{
    private $username;
    private $level;
    private $connect;
    /**
     * @author  hiendv
     * @description ??????
     */
    public function __construct($username,$level){
        $this->username = $username;
        $this->level = $level;
        $this->connect = new ConnectionDatabase();
    }
     /**
     * @author Hiendv
     * @param $parrent_menu
     * @param $menu_level
     * @description ????????????????
     */
    function load_Menu($parrent_menu,$menu_level){
        $mysqli = $this->connect->getMysqli();
		$db_name = $this->connect->getDB_name();
		$sql = "SELECT a.* FROM $db_name.menu a,$db_name.menu_access b where b.user_level='$this->level' and b.menu_id= a.menu_id and a.parent_menu='$parrent_menu' and a.menu_level='$menu_level' ";
        //echo $sql;
        $result = $mysqli->query($sql);
        $i=0;
        $rs=NULL;
	 	while($row = $result->fetch_array(MYSQLI_ASSOC))
	 	{
	 	     $rs[$i][0]= $row['menu_ID'];
             //echo($rs[$i][0]."<br/>");
             $rs[$i][1]= $row['menu_name'];
             $rs[$i][2]= $row['parent_menu'];
             $rs[$i][3]= $row['menu_level'];
             $rs[$i][4]= $row['menu_order'];
			 $rs[$i][5]= $row['menu_file'];
            
             $lv = $rs[$i][3]+1;
             $pr = $rs[$i][0]+0;
             $i=$i+1;
             $sql_submenu = "SELECT a.* FROM $db_name.menu a,$db_name.menu_access b where b.user_level='$this->level' and b.menu_id= a.menu_id and a.parent_menu='$pr' and a.menu_level='$lv'";
            //printf($sql_submenu);
             $submenu_rs = $mysqli->query($sql_submenu);
             while($row_submenu = $submenu_rs->fetch_array(MYSQLI_ASSOC)){
                 $rs[$i][0]= $row_submenu['menu_ID'];
                 $rs[$i][1]= $row_submenu['menu_name'];
                 $rs[$i][2]= $row_submenu['parent_menu'];
                 $rs[$i][3]= $row_submenu['menu_level'];
                 $rs[$i][4]= $row_submenu['menu_order'];
				 $rs[$i][5]= $row_submenu['menu_file'];
                 
                 $i=$i+1;
             }
             $submenu_rs->close();
	 	}
        $result->close();
	 	return $rs;
    }
    
}

?>